package com.cj.wanandroid

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.TextView
import androidx.lifecycle.lifecycleScope
import com.cj.mainmodule.MainActivity
import kotlinx.coroutines.*

class SplashActivity : AppCompatActivity() {
    companion object{
        private const val TAG = "SplashActivity"
    }
    private lateinit var count:TextView
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.splash_activity_main)
        count = findViewById(R.id.count)
        Log.d(TAG, "onCreate: ----------start")
        lifecycleScope.launch(Dispatchers.Main) {
            Log.d(TAG, "launch: start ${Thread.currentThread().name}")
            for (i in 3 downTo 1){
                count.text = "${i}s"
                delay(1000)//遇到挂起函数
            }
            Log.d(TAG, "launch: end ${Thread.currentThread().name}")
            startActivity(Intent(this@SplashActivity,MainActivity::class.java))
            this@SplashActivity.finish()

        }
        Log.d(TAG, "onCreate: ----------end")
    }

}